// -------buffer的实例方法
// buf.write(string[, offset[, length]][, encoding])
// buf.fill(value[, offset][, end])
const buffer3 = Buffer.alloc(100);
// buffer3.write("hello world", 0, "utf8");
buffer3.fill("我要吃大米饭，我要吃大菠萝，我要吃刀子");
console.log(buffer3.toString(), "fill方法");

console.log(buffer3.slice(0, 3).toString(), "slice方法");
console.log(buffer3.indexOf("吃"), "indexOf方法");

const buffer4 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);

const json = JSON.stringify(buffer4);
console.log(buffer4.toJSON());

// 输出: {"type":"Buffer","data":[1,2,3,4,5]}
console.log(json);
